package com.findbus.project;

import android.support.v4.app.FragmentActivity;

import com.entity.Login;
import com.findbus.activity.LoginActivity;
import com.findbus.activity.MainActivity;
import com.findbus.activity.WelcomActivity;
import com.util.tool.SharedPreferencesHelp;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

public class HomeActivity extends FragmentActivity {
	private boolean isLogin;
	private boolean isFirst;
	private Login login;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home);
		initData();
		initView();
	}

	private void initData() {
		SharedPreferences help = SharedPreferencesHelp.getInstanceSharedPreferencesHelp(this);
		isFirst = help.getBoolean("isFirst", false);
		isLogin = help.getBoolean("isLogin", false);
		login = new Login();
		login.setId(help.getString("id", null));
	}

	private void initView() {

		new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				if (!isFirst)
					startActivity(new Intent(HomeActivity.this, WelcomActivity.class));
				else if (!isLogin)
					startActivity(new Intent(HomeActivity.this, LoginActivity.class));
				else {
					Intent intent = new Intent(HomeActivity.this, MainActivity.class);
					Bundle bundle = new Bundle();
					bundle.putSerializable("login", login);
					intent.putExtras(bundle);
					startActivity(intent);
				}
				finish();
			}
		}).start();
	}

}
